home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / esc.jar / com / extensibility / xa / BaseSourcePane.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-06-30  |  8.3 KB  |  272 lines

  1. package com.extensibility.xa;
  2.  
  3. import com.extensibility.app.BaseAction;
  4. import com.extensibility.app.BaseDocument;
  5. import com.extensibility.app.BaseUndoable;
  6. import com.extensibility.app.DialogFactory;
  7. import com.extensibility.app.UI;
  8. import com.extensibility.rock.RButton;
  9. import com.extensibility.rock.SimpleListPopup;
  10. import com.extensibility.xml.ExternalSubset;
  11. import com.extensibility.xml.ParserException;
  12. import com.extensibility.xml.URI;
  13. import java.awt.Cursor;
  14. import java.awt.Font;
  15. import java.awt.Insets;
  16. import java.awt.event.ActionEvent;
  17. import java.util.Enumeration;
  18. import java.util.Vector;
  19. import javax.swing.JButton;
  20. import javax.swing.JComponent;
  21. import javax.swing.JScrollPane;
  22. import javax.swing.JTextArea;
  23. import javax.swing.event.UndoableEditListener;
  24. import javax.swing.text.BadLocationException;
  25. import javax.swing.text.DefaultEditorKit;
  26. import javax.swing.undo.UndoManager;
  27.  
  28. public abstract class BaseSourcePane extends CompositePane {
  29.    JTextArea sourceText = new 1((BaseSourcePane)null);
  30.    JScrollPane sourceScroll;
  31.    JButton modulePicker;
  32.    boolean dirty = false;
  33.    boolean inSync = false;
  34.    boolean inReparse = false;
  35.    boolean ignoreMyCommitPending = false;
  36.    boolean inRefresh = false;
  37.    URI uri;
  38.    UndoableEditListener undoListener;
  39.    SourceUndoManager undoManager = new SourceUndoManager((BaseSourcePane)null);
  40.    SchemaDocListener docListener = new 5(this);
  41.    BaseAction refreshAction = null;
  42.    BaseAction parseAction = null;
  43.  
  44.    public BaseSourcePane(SchemaDoc var1) {
  45.       super(var1);
  46.       Font var2 = UI.getSrcFont();
  47.       if (var2 != null) {
  48.          this.sourceText.setFont(var2);
  49.       }
  50.  
  51.       this.sourceText.setMargin(new Insets(4, 4, 4, 4));
  52.       this.sourceScroll = new JScrollPane(this.sourceText);
  53.       this.sourceText.setCursor(Cursor.getPredefinedCursor(2));
  54.       this.sourceText.getDocument().addDocumentListener(new 2(this));
  55.       ((CompositePane)this).getSchemaDoc().addDocumentListener(this.docListener);
  56.       this.undoListener = new MyUndoableEditListener(this);
  57.       this.sourceText.getDocument().addUndoableEditListener(this.undoListener);
  58.       this.modulePicker = new JButton(String.valueOf(this.getHeaderPrefix()).concat(String.valueOf(((CompositePane)this).getSchemaDoc().getURI().getFullName())));
  59.       this.modulePicker.addMouseListener(new 3(this));
  60.       this.uri = ((BaseDocument)var1).getURI();
  61.       CompositePane.setHeader(this.sourceScroll, this.modulePicker, new RButton(this.createParseAction()));
  62.    }
  63.  
  64.    public void showError(ParserException var1) {
  65.       int var2 = var1.getSourceLinePos() - 1;
  66.  
  67.       try {
  68.          int var3 = this.sourceText.getLineStartOffset(var2);
  69.          int var4 = this.sourceText.getLineEndOffset(var2);
  70.          this.sourceText.select(var3, var4);
  71.       } catch (BadLocationException var5) {
  72.       }
  73.  
  74.    }
  75.  
  76.    protected void addSetURIAction(Vector var1, ExternalSubset var2) {
  77.       URI var3 = var2.getSystemURI();
  78.       boolean var4 = this.uri.equals(var3);
  79.       String var5 = var3.getShortName();
  80.       if (var5.length() == 0) {
  81.          var5 = UI.getString("untitled.window");
  82.       }
  83.  
  84.       if (var4) {
  85.          var5 = String.valueOf("* ").concat(String.valueOf(var5));
  86.       }
  87.  
  88.       SimpleListPopup.ListEntry var6 = new SimpleListPopup.ListEntry(var5, new 4(var3, this));
  89.       var1.addElement(var6);
  90.       Enumeration var7 = var2.children();
  91.  
  92.       while(var7.hasMoreElements()) {
  93.          this.addSetURIAction(var1, (ExternalSubset)var7.nextElement());
  94.       }
  95.  
  96.    }
  97.  
  98.    public void uriUpdateNotify(URI var1, URI var2) {
  99.       if (this.uri.equals(var1)) {
  100.          this.uri = var2;
  101.          this.modulePicker.setText(String.valueOf(this.getHeaderPrefix()).concat(String.valueOf(this.uri.getFullName())));
  102.       }
  103.  
  104.    }
  105.  
  106.    public JComponent getComponent() {
  107.       return this.sourceScroll;
  108.    }
  109.  
  110.    public boolean setURI(URI var1) {
  111.       if (!this.commitPendingEdits(true)) {
  112.          return false;
  113.       } else {
  114.          this.uri = var1;
  115.          this.modulePicker.setText(String.valueOf(this.getHeaderPrefix()).concat(String.valueOf(var1.getFullName())));
  116.          this.inSync = false;
  117.          if (this.isAdded()) {
  118.             this.refresh();
  119.          }
  120.  
  121.          return true;
  122.       }
  123.    }
  124.  
  125.    public void discard() {
  126.       this.inSync = false;
  127.       this.dirty = false;
  128.    }
  129.  
  130.    public boolean commitPendingEdits(boolean var1) {
  131.       if (this.ignoreMyCommitPending) {
  132.          return true;
  133.       } else {
  134.          if (this.dirty) {
  135.             int var2 = XADialogFactory.askParseChanges(this.getComponent());
  136.             if (var2 == 0) {
  137.                return false;
  138.             }
  139.  
  140.             if (var2 == 1) {
  141.                this.discard();
  142.             } else {
  143.                this.parseAction.actionOccurred((ActionEvent)null);
  144.             }
  145.          }
  146.  
  147.          return true;
  148.       }
  149.    }
  150.  
  151.    public boolean isAdded() {
  152.       return this.getComponent().getParent() != null;
  153.    }
  154.  
  155.    public boolean addRequest() {
  156.       return true;
  157.    }
  158.  
  159.    protected void setDirty(boolean var1) {
  160.       this.dirty = var1;
  161.       if (!this.dirty) {
  162.          this.inSync = true;
  163.       }
  164.  
  165.    }
  166.  
  167.    protected boolean isDirty() {
  168.       return this.dirty;
  169.    }
  170.  
  171.    protected boolean isInSync() {
  172.       return this.inSync;
  173.    }
  174.  
  175.    protected void setInSync(boolean var1) {
  176.       this.inSync = var1;
  177.    }
  178.  
  179.    protected boolean hasDeclTable() {
  180.       return false;
  181.    }
  182.  
  183.    public String getClassName() {
  184.       return "com.extensibility.xa.BaseSourcePane";
  185.    }
  186.  
  187.    protected void checkJDKBug() {
  188.       if (this.sourceText.getLineCount() > 1024) {
  189.          DialogFactory.caution(this.getComponent(), UI.getString("bug.jdk.textarea.size"));
  190.       }
  191.  
  192.    }
  193.  
  194.    protected abstract void refresh();
  195.  
  196.    protected abstract String getHeaderPrefix();
  197.  
  198.    protected abstract BaseUndoable createSourceRefreshUndoable();
  199.  
  200.    protected abstract BaseUndoable createSourceReparseUndoable();
  201.  
  202.    protected void dataChanged() {
  203.       if (!this.inReparse) {
  204.          this.inSync = false;
  205.          if (this.isAdded() && !this.isDirty()) {
  206.             this.refresh();
  207.          }
  208.  
  209.       }
  210.    }
  211.  
  212.    public JTextArea getSourceText() {
  213.       return this.sourceText;
  214.    }
  215.  
  216.    protected abstract BaseAction createRefreshAction();
  217.  
  218.    protected abstract BaseAction createParseAction();
  219.  
  220.    protected BaseAction createUndoAction() {
  221.       return this.undoManager.getUndoAction();
  222.    }
  223.  
  224.    protected BaseAction createRedoAction() {
  225.       return this.undoManager.getRedoAction();
  226.    }
  227.  
  228.    public void cut() {
  229.       (new DefaultEditorKit.CutAction()).actionPerformed((ActionEvent)null);
  230.    }
  231.  
  232.    public void copy() {
  233.       (new DefaultEditorKit.CopyAction()).actionPerformed((ActionEvent)null);
  234.    }
  235.  
  236.    public void paste() {
  237.       (new DefaultEditorKit.PasteAction()).actionPerformed((ActionEvent)null);
  238.    }
  239.  
  240.    public void clear() {
  241.       this.sourceText.replaceSelection("");
  242.    }
  243.  
  244.    public boolean find(String var1, boolean var2) {
  245.       String var3 = this.sourceText.getText();
  246.       int var4 = var3.indexOf(var1, var2 ? 0 : this.sourceText.getSelectionStart() + 1);
  247.       if (var4 >= 0) {
  248.          this.sourceText.select(var4, var4 + var1.length());
  249.          return true;
  250.       } else {
  251.          return var2 ? false : this.find(var1, true);
  252.       }
  253.    }
  254.  
  255.    public String getSelectedText() {
  256.       return this.sourceText.getSelectedText();
  257.    }
  258.  
  259.    public boolean setSelectedText(String var1) {
  260.       if (!this.sourceText.isEditable()) {
  261.          return false;
  262.       } else {
  263.          this.sourceText.replaceSelection(var1);
  264.          return true;
  265.       }
  266.    }
  267.  
  268.    public UndoManager getUndoManager() {
  269.       return this.undoManager;
  270.    }
  271. }
  272.